﻿namespace Smart.Utils.Security2
{
    using System;
    using System.IO;
    using System.Security.Cryptography;

    public class Encryptor
    {
        private Smart.Utils.Security2.EncryptEngine engin;
        public byte[] IV;

        public Encryptor(EncryptionAlgorithm algID, string key)
        {
            this.engin = new Smart.Utils.Security2.EncryptEngine(algID, key);
        }

        public string Encrypt(string MainString)
        {
            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, this.engin.GetCryptTransform(), CryptoStreamMode.Write);
            StreamWriter writer = new StreamWriter(stream2);
            writer.WriteLine(MainString);
            writer.Close();
            stream2.Close();
            this.IV = this.engin.Vector;
            byte[] inArray = stream.ToArray();
            stream.Close();
            return Convert.ToBase64String(inArray);
        }

        public Smart.Utils.Security2.EncryptEngine EncryptEngine
        {
            get
            {
                return this.engin;
            }
            set
            {
                this.engin = value;
            }
        }
    }
}

